<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AJAX测试发送请求</title>
</head>
    <script>
        function getFile() {
            var xmlhttp;
            if(window.XMLHttpRequest){
                xmlhttp=new XMLHttpRequest();
            }
            else{
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            
            xmlhttp.onreadystatechange=function(){
                if(xmlhttp.status==200 && xmlhttp.readyState==4){
                    console.log(xmlhttp.innerText);
                    console.log(xmlhttp);
                    document.getElementById("myDiv").innerText=xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET","./ajax_test.txt",true);
            xmlhttp.send();
        }

    </script>


<body>
    <h2>AJAX</h2>
    <button id="btn" onclick="getFile()">发送请求</button>
    <div id="myDiv"></div>

    
</body>
</html>